package com.sc.nft.task;

import com.sc.nft.dao.UserPledgeRecordsDao;
import com.sc.nft.entity.UserPledgeRecords;
import com.sc.nft.helper.UserPledgeRecordsHandler;
import com.sc.nft.service.DaoPledgeService;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.util.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
@RequiredArgsConstructor
@Slf4j
public class PledgeTask {


    private final UserPledgeRecordsDao userPledgeRecordsDao;
    @Resource
    private UserPledgeRecordsHandler userPledgeRecordsHandler;
    private final DaoPledgeService daoPledgeService;

    @XxlJob("pledgeTaskAward")
    public void pledgeTaskAward() throws Exception {

        log.info("质押任务奖励开始执行时间:{}", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        //获取一分钟后质押完成的数据
        List<UserPledgeRecords> list = userPledgeRecordsDao.getListOneMinuteLater();
        if (list.size() > 0) {
            userPledgeRecordsHandler.start(list);
        }

    }


    @XxlJob("pledgeSettleTask")
    public void pledgeSettleTask() throws Exception {
        log.info("质押(燕琅嬛)结算开始执行时间:{}", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        daoPledgeService.settlePledge();
    }


}
